package com.tensquare.qa.dao;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.tensquare.qa.pojo.Problem;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 数据访问接口
 * @author Administrator
 *
 */
public interface ProblemDao extends JpaRepository<Problem,String>,JpaSpecificationExecutor<Problem>{

    // 最新问答
    @Query(value = "SELECT * FROM tb_pl, tb_problem WHERE problemid=id AND labelid = ? ORDER BY replytime DESC", nativeQuery = true)
    public Page<Problem> newlist(String problemid, Pageable pageable);

    // 热门问答列表
    @Query(value = "SELECT * FROM tb_pl, tb_problem WHERE problemid=id AND labelid = ? ORDER BY reply DESC", nativeQuery = true)
    public Page<Problem> hotlist(String problemid, Pageable pageable);

    // 等待问答列表
    @Query(value = "SELECT * FROM tb_pl, tb_problem WHERE problemid=id AND labelid = ? AND reply=0 ORDER BY createtime", nativeQuery = true)
    public Page<Problem> waitlist(String problemid, Pageable pageable);

}
